package com.github.prontera.config;

import java.util.LinkedList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ResponseMessageBuilder;
import springfox.documentation.service.ResponseMessage;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import com.github.prontera.StatusCode;
import com.github.prontera.model.swagger.SwaggerApiInfo;

/**
 * @author Alex
 */
@EnableSwagger2
@Configuration
public class SwaggerConfiguration extends SwaggerTemplate {

	@Bean
	public SwaggerApiInfo info() {
		SwaggerApiInfo swaggerApiInfo = new SwaggerApiInfo();
		swaggerApiInfo.setTitle("Trade Manage");
		swaggerApiInfo.setStatusList(extractStatusCodes());
		swaggerApiInfo.setVersion("v1.0.0");
		return swaggerApiInfo;
	}

	private List<ResponseMessage> extractStatusCodes() {
		final LinkedList<ResponseMessage> list = new LinkedList<ResponseMessage>();
		for (StatusCode statusCodes : StatusCode.values()) {
			list.add(new ResponseMessageBuilder().code(statusCodes.code()).message(statusCodes.message()).build());
		}
		return list;
	}

}
